'use strict';

window.vs_env = window.ENV = 
{ APPNAME: '智能机器人',
  RESOURCE_BASE: '/',
  API_URL: 'http://localhost/api/rest',
  MODULES: 
   [ 'ui.router',
     'templates',
     'ui.bootstrap',
     'ngResource',
     'ngNotify',
     'mwl.confirm',
     'ngFileUpload',
     'ngAnimate',
     'LocalStorageModule',
     'monospaced.qrcode',
     'angular-loading-bar',
     'scroll',
     'ngCookies',
     'ui.select',
     'ngSanitize' ] };
window.appModule = angular.module("App", window.vs_env.MODULES);
(function(angular,window,document){
window.appModule
    .run(["$cacheFactory", "$rootScope", "$log", "$state", "confirmationPopoverDefaults", "localStorageService", "ngNotify", "$cookies", function ($cacheFactory,$rootScope,$log,$state,confirmationPopoverDefaults,localStorageService,ngNotify, $cookies) {
        //对路由错误做统一处理
        $rootScope.$on('$stateChangeError',routeErrorFn);
        $rootScope.$on('$stateNotFound',routeErrorFn);
        ngNotify.config({
            position: 'top',
            duration: 1000
        });
        function routeErrorFn(e){
            $log.error('router error ');
        }

        $rootScope.$on('$stateChangeStart',function(event, toState, toParams, fromState, fromParams){
            if(toState.name=='loginQR' || toState.name=='loginAccount')return;// 如果是进入登录界面则允许
            // 如果用户不存在
            var user = $cookies.getObject('user');
            console.log('user:'+user);
            if(!user || !user.token){
                ngNotify.set("您尚未登录, 请先登录", 'error');
                event.preventDefault();// 取消默认跳转行为
                $state.go("loginQR",{from:fromState.name,w:'notLogin'});//跳转到登录界面
            }
        });

    }]);
window.appModule.factory('authService',["$rootScope", "$injector", "$cookies", "$location", function($rootScope, $injector, $cookies, $location){
    return {
        request: function(config){
            var user = $cookies.getObject('user');
            if (user){
                var token = user.token;
                console.log('token is '+token);
                config.headers['token'] = token;
            }
            return config;
        },
        response: function (response) {
            if(response.data.messageCode == "90001"){
                //未登录 跳转到登录页面
                var ngNotify = $injector.get('ngNotify');
                ngNotify.set('您长时间未操作, 需要重新登录', 'error');
                $location.path('/login');
            }
            return response;
        },
        responseError: function (response) {
            var ngNotify = $injector.get('ngNotify');
            ngNotify.set('未知错误', 'error');
            return response;
        }
    };
}]);

window.appModule.config(["$provide", "$stateProvider", "$urlRouterProvider", "$httpProvider", function($provide, $stateProvider, $urlRouterProvider, $httpProvider){
    $httpProvider.interceptors.push('authService');
    $urlRouterProvider.when('/', '/login');
    $urlRouterProvider.when('', '/login');

}]);


})(angular,window,document);
(function(angular,window,document){
/**
 * Created by Sin on 2016-10-7.
 */

//app/test/controller.js start
var errorMsg="小宝自检中,请稍后再来看望小宝...";

var timer;

window.appModule.controller('LoginControl', ["$rootScope", "$scope", "$http", "$state", "ngNotify", "$cookies", "$interval", function ($rootScope, $scope, $http, $state, ngNotify, $cookies,$interval) {
    $interval.cancel(timer);
    $scope.countryList = [
        {value:'86',name:'+86'}
    ];
    $scope.selected = { areaCode: $scope.countryList[0] };
    $scope.login = function () {
        $http({
            method: 'POST',
            url: ENV['API_URL']+'/loginByAccount',
            data: {countryAreaCode:$scope.selected.areaCode.value,phoneNumber: $scope.phoneNumber,password:$scope.password}
        }).success(function(data){
            if(data.messageCode=='10000') {
                // this callback will be called asynchronously
                $rootScope.user = data.user;
                $cookies.putObject('user', $rootScope.user);
                $state.go("robotList");
            }else {
                ngNotify.set(data.messageText, 'error');
            }
        }).error(function(){
            ngNotify.set(errorMsg, 'warn');
        });
        /*if($scope.username == 'admin'){
            $rootScope.user = {
                userId : 'afda807e53ae69a40153c05f69d200dc',
                userName : 'XXX',
                token : 'jj32j3je23jej32knelg3gfwjk323r3'
            }
            $cookies.putObject('user', $rootScope.user);
            $state.go("robotList");
        }else{
            ngNotify.set('用户名不正确', 'error');
        }*/
    };
}]);

window.appModule.controller('LoginQRControl', ["$rootScope", "$scope", "$http", "$state", "ngNotify", "$interval", "$cookies", function ($rootScope,$scope, $http, $state, ngNotify,$interval,$cookies) {
    $http.post(ENV['API_URL']+'/openfaqserver/getQrCode.action').success(function(data){
        if(data.messageCode=='10000'){
            $scope.url=data.qrcodeStr;
            timer=$interval(function(){
                $http({
                    method: 'POST',
                    url: ENV['API_URL']+'/loginByQr',
                    data: {qrcodeStr: $scope.url},
                    ignoreLoadingBar: true
                }).success(function(data){
                    // this callback will be called asynchronously
                    if(data.messageCode=='10000') {
                        $rootScope.user = data.user;
                        $cookies.putObject('user', $rootScope.user);
                        $interval.cancel(timer);
                        $state.go("robotList");
                    }
                    // when the response is available
                }).error(function(){
                    ngNotify.set(errorMsg, 'warn');
                    $interval.cancel(timer);
                });
            },2000);
        }
    }).error(function(){
        ngNotify.set(errorMsg, 'warn');
    });
}]);

//app/test/controller.js end
})(angular,window,document);
(function(angular,window,document){
window.appModule.config(["$stateProvider", function($stateProvider){
    //定义首页路由
    $stateProvider
        .state('loginQR',{
            url: '/login',
            templateUrl: 'login/login_QR'
        })
        .state('loginAccount',{
            url: '/loginact',
            templateUrl: 'login/login_account'
        })

}]);


})(angular,window,document);
(function(angular,window,document){
/**
 * Created by Deng on 2016-10-16.
 */

window.appModule.controller('QuestionAdd', ["$scope", "$http", "$state", "$stateParams", "Upload", "ngNotify", "questionEditAPI", "$cookies", function ($scope,$http,$state,$stateParams, Upload, ngNotify, questionEditAPI,$cookies) {
    $scope.question = {
        type: "none",
        videoUrl: "",
        question:"",
        answer:""
    }

    questionEditAPI.getRobotById({robotId:$cookies.getObject('robotId')}, function(result){
        if(result.messageCode == "10000"){
            $scope.robotName = result.robot.nickname;
            $scope.robotIcon = result.robot.imageUrl;
            $scope.useNum = result.robot.usedQuestionCount;
            $scope.totalNum = result.robot.maxQuestionCount;
        }else{
            ngNotify.set(result.messageText, 'error');
        }
    });

    $scope.file = null;
    $scope.question.robotId = $stateParams.robotId;

    $scope.saveQuestion = function () {
        if($scope.question.question == "" || $scope.question.answer == "") {
            ngNotify.set('问题和回答不能为空', 'warn');
            return ;
        }
        console.log($scope.question.imageDuration);
        if($scope.question.imageDuration && !/^[0-9]*$/.test($scope.question.imageDuration)){
            ngNotify.set('展示时间只能为正整数', 'warn');
            return;
        }
        if($scope.question.type =="image" && (null == $scope.file || "undefined" == $scope.file.name)) {
            ngNotify.set('请选择图片', 'warn');
            return;
        }
        if($scope.question.type =="video" && $scope.question.videoUrl =="") {
            ngNotify.set('视频地址不能为空', 'warn');
            return;
        }
        if($scope.question.videoUrl !="" && $scope.question.videoUrl.indexOf("youku.com") < 0 ){
            ngNotify.set('视频地址必须为优酷视频地址', 'warn');
            return;
        }

        //首先上传图片
        if( $scope.file){
            console.log("开始上传附件...");
            uploadAttachment($scope,  $scope.file, Upload, function (data, status, headers, config) {
                if(status == 200){
                    //保存问题到后台 暂时图片的url尚未设置保存
                    console.log("保存问题到后台...");
                    $scope.question.imageName = data.content;
                    console.log($scope.question);
                    saveQuestion($scope.question, null, questionEditAPI, ngNotify, saveSuccessCallback);
                }else {
                    ngNotify.set('图片上传失败!', 'error');
                }
                //上传成功
                console.log('file ' + config.file.name + 'uploaded. Response: ' + data);
            });
        } else {
            saveQuestion($scope.question, null, questionEditAPI, ngNotify, saveSuccessCallback);
        }
        $state.go('questionList',{robotId:$scope.question.robotId}, {reload: true});
    };

    function saveSuccessCallback(){
        $state.go('questionList');
    }

}])

window.appModule.controller('QuestionEdit', ["$scope", "$http", "$state", "$stateParams", "Upload", "ngNotify", "questionEditAPI", "$cookies", "$location", function ($scope,$http,$state,$stateParams, Upload, ngNotify, questionEditAPI,$cookies,$location) {
    $scope.question = {
        type: "none",
        videoUrl: ""
    }
    $scope.tmpParams = null;

    questionEditAPI.getRobotById({robotId:$cookies.getObject('robotId')}, function(result){
        if(result.messageCode == "10000"){
            $scope.robotName = result.robot.nickname;
            $scope.robotIcon = result.robot.imageUrl;
            $scope.useNum = result.robot.usedQuestionCount;
            $scope.totalNum = result.robot.maxQuestionCount;
        }else{
            ngNotify.set(result.messageText, 'error');
        }

    });

    console.log("从后台加载数据");
    if(":questionId" != $stateParams.questionId){
        $cookies.putObject('questionId', $stateParams.questionId);
    };

    $scope.question.robotId = $stateParams.robotId;
    $scope.question.questionId = $stateParams.questionId;
    questionEditAPI.queryQuestionDetail({questionId: $cookies.getObject('questionId')}, function(result){
        if(result.messageCode == "10000"){
            $scope.question.question = result.question.question;
            $scope.question.answer = result.question.answer;
            $scope.question.imageDuration = result.question.imageDuration;
            $scope.file = result.question.imageUrl;
            $scope.question.imageName = result.question.imageUrl;


            // 如果有图片数据则问题类型为视频类型
            if(result.question.videoUrl != "") {
                $scope.question.type="video";
                $scope.question.videoUrl=result.question.videoUrl;
            } else if(result.question.imageUrl != "") {
                $scope.question.type="image";
                $scope.question.imageUrl=result.question.imageUrl;
            }
        }else{
            ngNotify.set(result.messageText, 'error');
        }
    });

    $scope.saveQuestion = function () {
        if($scope.question.question == "" || $scope.question.answer == "") {
            ngNotify.set('问题和回答不能为空', 'warn');
            return ;
        }
        if($scope.question.imageDuration !="" && !/^[0-9]*$/.test($scope.question.imageDuration)){
            ngNotify.set('展示时间只能为正整数', 'warn');
            return;
        }
        if($scope.question.type =="image" && (null == $scope.file || "undefined" == $scope.file.name)) {
            ngNotify.set('请选择图片', 'warn');
            return;
        }
        if($scope.question.type =="video" && $scope.question.videoUrl =="") {
            ngNotify.set('视频地址不能为空', 'warn');
            return;
        }
        if($scope.question.videoUrl !="" && $scope.question.videoUrl.indexOf("youku.com") < 0 ){
            ngNotify.set('视频地址必须为优酷视频地址', 'warn');
            return;
        }
        if($scope.question.type =="image") {
            $scope.question.videoUrl="";
        } else if($scope.question.type =="video") {
            $scope.file = null;
        } else {
            $scope.file = null;
            $scope.question.videoUrl="";
        }

        //首先上传图片
        if( $scope.file && $scope.file.name != null){
            console.log("开始上传附件...");
            uploadAttachment($scope,  $scope.file, Upload, function (data, status, headers, config) {
                if(status == 200){
                    //保存问题到后台 暂时图片的url尚未设置保存
                    console.log("保存问题到后台...");
                    $scope.question.imageName = data.content;
                    saveQuestion($scope.question, null, questionEditAPI, ngNotify, saveSuccessCallback);
                }else {
                    ngNotify.set('图片上传失败!', 'error');
                }
                //上传成功
                console.log('file ' + config.file.name + 'uploaded. Response: ' + data);
            });
            $scope.question.imageName=$scope.file.name;
        } else {

            $scope.question.imageName = 'qm'+$scope.question.imageName.substr($scope.question.imageName.lastIndexOf('/') , $scope.question.imageName.length);
            saveQuestion($scope.question, null, questionEditAPI, ngNotify, saveSuccessCallback);
        }
        $state.go("questionList",{robotId:$scope.question.robotId}, {reload: true});
    };

    function saveSuccessCallback(){
        $state.go('questionList');
    }
}])

window.appModule.controller('BotInfo', ["$scope", "$http", "$state", function ($scope,$http,$state) {
    var botInfo = {
        totalCount: '4000',
        usedCount:'999'
    };
    setQuestionCount($scope, botInfo);
}])

function setQuestionCount($scope, botInfo){
    if(botInfo){
        $scope.totalCount = botInfo.totalCount;
        $scope.usedCount=botInfo.usedCount;
    }else {
        console.log('BotInfo is undefind');
    }
}

function uploadAttachment($scope, file, Upload, uploadSuccess){
    Upload.upload({
        //服务端接收
        url: ENV['API_URL']+'/upload',
        //上传的同时带的参数
        data: { 'filename': file.name, 'filelength': file.size },
        file: file
    }).progress(function (evt) {
        //进度条
        var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
        console.log('progess:' + progressPercentage + '%' + evt.config.file.name);
    }).success(uploadSuccess).error(function (data, status, headers, config) {
        //上传失败
        console.log('error status: ' + status);
    });
}



function saveQuestion(question, imgUrl, questionEditAPI, ngNotify, callback){
    if(question){
        if(imgUrl){
            question.imgUrl = imgUrl;
        }

        if(question.questionId) {
            //选择图片则清空视频数据
            if(question.type=="image") {
                question.videoUrl="";
            } else if(question.type=="video") {
                //选择视频则清空图片数据
                question.imageName="";
            } else {
                question.videoUrl="";
                question.imageName="";
            }
            questionEditAPI.updateQuestion(question, function(result){
                if(result.messageCode != "10000"){
                    ngNotify.set(result.messageText, 'error');
                }
                //ngNotify.set(result.messageCode, 'info');
            })
        } else {
            questionEditAPI.saveQuestion(question, function(result){
                //ngNotify.set(result.messageCode, 'info');
                if(result.messageCode != "10000"){
                    ngNotify.set(result.messageText, 'error');
                }
            })
        }
    }else {
        console.log("question 对象为空");
    }
}


})(angular,window,document);
(function(angular,window,document){
window.appModule.controller('listControl', ["$scope", "$http", "$state", "$stateParams", "questionListAPI", "ngNotify", "$cookies", function ($scope,$http,$state,$stateParams,questionListAPI,ngNotify,$cookies) {
    if(":robotId" != $stateParams.robotId){
        $cookies.putObject('robotId', $stateParams.robotId);
    };
    //问题保存、更新时刷新速度太快,需要挂起等待100毫秒
    sleep(100);
    questionListAPI.getRobotById({robotId:$cookies.getObject('robotId')}, function(result){
        if(result.messageCode == "10000"){
            $scope.robotName = result.robot.nickname;
            $scope.robotId = result.robot.id;
            $scope.robotIcon = result.robot.imageUrl;
            $scope.useNum = result.robot.usedQuestionCount;
            $scope.totalNum = result.robot.maxQuestionCount;
        }else{
            ngNotify.set(result.messageText, 'error');
        }
    });
    questionListAPI.getQuestionsByRobotId({robotId:$cookies.getObject('robotId'),pageIndex:0,pageSize:10}, function(result){
        if(result.messageCode == "10000"){
            $scope.questions = result.questionList;
            $scope.pageIndex = result.pageIndex+1;
            $scope.pageCount = result.pageCount;
            $cookies.putObject('isSearch', 0);
        }else{
            ngNotify.set(result.messageText, 'error');
        }
    });
    $scope.loadMore = function(){
        if($scope.pageIndex < $scope.pageCount){
            if(1 == $cookies.getObject('isSearch')){
                questionListAPI.getQuestionsByParam({robotId:$cookies.getObject('robotId'),pageIndex:$scope.pageIndex,pageSize:10,questionOrAnswer:$scope.param}, function(result){
                    if(result.messageCode == "10000"){
                        $scope.pageIndex = $scope.pageIndex+1;
                        for (var i in result.questionList) {
                            $scope.questions.push(result.questionList[i]);
                        }
                    }else{
                        ngNotify.set(result.messageText, 'error');
                    }
                });
            }else{
                questionListAPI.getQuestionsByRobotId({robotId:$cookies.getObject('robotId'),pageIndex:$scope.pageIndex,pageSize:10}, function(result){
                    if(result.messageCode == "10000"){
                        $scope.pageIndex = $scope.pageIndex+1;
                        for (var i in result.questionList) {
                            $scope.questions.push(result.questionList[i]);
                        }
                    }else{
                        ngNotify.set(result.messageText, 'error');
                    }
                });
            }
        }
    };
    $scope.search = function(){
        if(undefined == $scope.param || null == $scope.param){
            $scope.param = "";
        }
        questionListAPI.getQuestionsByParam({robotId:$cookies.getObject('robotId'),pageIndex:0,pageSize:10,questionOrAnswer:$scope.param}, function(result){
            if(result.messageCode == "10000"){
                $scope.questions = result.questionList;
                $scope.pageIndex = result.pageIndex+1;
                $scope.pageCount = result.pageCount;
                $cookies.putObject('isSearch', 1);
            }else{
                ngNotify.set(result.messageText, 'error');
            }
        });
    };
    $scope.myVar = true;
    $scope.deleteId;
    $scope.deleteQuestion = function(id) {
        console.log(id);
        $scope.deleteId = id;
        $scope.myVar = !$scope.myVar;
    };

    $scope.deleteCanel = function() {
        $scope.myVar = !$scope.myVar;
    };

    //删除问题
    $scope.deleteConfirm = function () {
        questionListAPI.deleteQuestion({questionId:$scope.deleteId}, function(result){
            ngNotify.set(result.message, 'info');
            questionListAPI.getRobotById({robotId:$cookies.getObject('robotId')}, function(result){
                $scope.useNum = result.robot.usedQuestionCount;
            });
            if(1 == $cookies.getObject('isSearch')){
                questionListAPI.getQuestionsByParam({robotId:$cookies.getObject('robotId'),pageIndex:0,pageSize:10,questionOrAnswer:$scope.param}, function(result){
                    if(result.messageCode == "10000"){
                        $scope.questions = result.questionList;
                        $scope.pageIndex = result.pageIndex+1;
                        $scope.pageCount = result.pageCount;
                    }else{
                        ngNotify.set(result.messageText, 'error');
                    }
                });
            }else{
                questionListAPI.getQuestionsByRobotId({robotId:$cookies.getObject('robotId'),pageIndex:0,pageSize:10}, function(result){
                    if(result.messageCode == "10000"){
                        $scope.questions = result.questionList;
                        $scope.pageIndex = result.pageIndex+1;
                        $scope.pageCount = result.pageCount;
                    }else{
                        ngNotify.set(result.messageText, 'error');
                    }
                });
            }
        });
        $scope.myVar = !$scope.myVar;
    };
}]);

function sleep(milliSeconds) {
    var startTime = new Date().getTime();
    while (new Date().getTime() < startTime + milliSeconds);
};

})(angular,window,document);
(function(angular,window,document){
/**
 * Created by Deng on 2016-10-16.
 */

factoryFn.$inject = ["$resource"];
window.appModule.factory('questionEditAPI',factoryFn);

function factoryFn($resource){
    var actions = {
        getRobotById: {
            url: ENV['API_URL']+'/openfaqserver/getRobotById.action',
            method: 'post'
        },
        saveQuestion: {
            url: ENV['API_URL']+'/openfaqserver/addQuestion.action',
            method: 'post'
        },
        updateQuestion: {
            url: ENV['API_URL']+'/openfaqserver/updateQuestion.action',
            method: 'post'
        },
        queryQuestionDetail: {
            url: ENV['API_URL']+'/openfaqserver/getQuestionById.action',
            method: 'post'
        }
    }
    return $resource('', {_ajaxWrapOption: {}},actions);
}
})(angular,window,document);
(function(angular,window,document){
factoryFn.$inject = ["$resource"];
window.appModule.factory('questionListAPI',factoryFn);

function factoryFn($resource){
    var actions = {
        getRobotById: {
            url: ENV['API_URL']+'/openfaqserver/getRobotById.action',
            method: 'post'
        },
        getQuestionsByRobotId: {
            url: ENV['API_URL']+'/openfaqserver/getQuestionsByRobotId.action',
            method: 'post'
        },
        getQuestionsByParam: {
            url: ENV['API_URL']+'/openfaqserver/searchQuestions.action',
            method: 'post'
        } ,
        deleteQuestion: {
            url: ENV['API_URL']+'/openfaqserver/deleteQuestion.action',
            method: 'post'
        }
    };
    return $resource('', {_ajaxWrapOption: {}},actions);
};
})(angular,window,document);
(function(angular,window,document){
window.appModule.config(["$stateProvider", function($stateProvider){
    $stateProvider
        .state('questionList',{
            params:{robotId:':robotId'},
            url: '/questionList',
            templateUrl: 'question/questionList',
            cache:false
        })

        .state('questionAdd',{
            params:{robotId:':robotId'},
            url: '/questionAdd',
            templateUrl: 'question/questionAdd'
        })

        .state('questionEdit',{
            params:{robotId:':robotId' , questionId:':questionId'},
            url: '/questionEdit',
            templateUrl: 'question/questionEdit'
        })
}]);


})(angular,window,document);
(function(angular,window,document){
/**
 * Created by Sin on 10/16/2016.
 */
// 定义模块
var scroll = angular.module('scroll', []);
// 定义滚动指令
scroll.directive('whenScrolled', function() {
    return function(scope, elm, attr) {
        // 内层DIV的滚动加载
        var raw = elm[0];
        elm.bind('scroll', function() {
            if (raw.scrollTop + raw.offsetHeight >= raw.scrollHeight) {
                scope.$apply(attr.whenScrolled);
            }
        });
    };
});
})(angular,window,document);
(function(angular,window,document){
/**
 * Created by Deng on 2016-10-7.
 */

//app/test/controller.js start

window.appModule.controller('robotControl', ["$scope", "$http", "$state", "robotAPI", "$cookies", "ngNotify", function ($scope,$http,$state,robotAPI,$cookies,ngNotify) {

    robotAPI.getUserById({userId:$cookies.getObject('user').id}, function(result){
        if(result.messageCode == "10000"){
            $scope.user = result.user;
        }else{
            ngNotify.set(result.messageText, 'error');
        }
    });
    robotAPI.getRobotsByUserId({userId:$cookies.getObject('user').id}, function(result){
        if(result.messageCode == "10000"){
            $scope.robots = result.robotList;
        }else{
            ngNotify.set(result.messageText, 'error');
        }
    });
    $scope.logOut = function() {
        robotAPI.logOut({userId:$cookies.getObject('user').id}, function(result){
            if(result.messageCode == "10000"){
                $cookies.putObject('user', "");
                $state.go("loginQR");
            }else{
                ngNotify.set(result.messageText, 'error');
            }
        });
    };
}]);

})(angular,window,document);
(function(angular,window,document){
factoryFn.$inject = ["$resource"];
window.appModule.factory('robotAPI',factoryFn);

function factoryFn($resource){
    var actions = {
        getUserById: {
            url: ENV['API_URL']+'/openfaqserver/getUserById.action',
            method: 'post'
        },
        getRobotsByUserId: {
            url: ENV['API_URL']+'/openfaqserver/getRobotsByUserId.action',
            method: 'post'
        },
        logOut: {
            url: ENV['API_URL']+'/openfaqserver/logOut.action',
            method: 'post'
        }
    };
    return $resource('', {_ajaxWrapOption: {}},actions);
};
})(angular,window,document);
(function(angular,window,document){
window.appModule.config(["$stateProvider", function($stateProvider){
    $stateProvider
        .state('robotList',{
            url: '/robotList',
            templateUrl: 'robot/robotList'
        })

}]);


})(angular,window,document);
(function(angular,window,document){
/**
 * Created by Deng on 2016-10-7.
 */

//app/test/controller.js start

window.appModule.controller('Test',["$scope", "testAPI", function($scope, testAPI){
    $scope.message = "我点击了它";
    testAPI.queryUser(null, function(result){
        toastr.success(JSON.stringify(result));
    });
    //toastr.success('更新成功');
}]);

//app/test/controller.js end
})(angular,window,document);
(function(angular,window,document){
/**
 * Created by Deng on 2016-10-7.
 */
//app/test/router.js start

window.appModule.config(["$stateProvider", function($stateProvider){
    //定义首页路由
    $stateProvider
        .state('test1',{
            url: '/test1',
            templateUrl: 'test/test1',
            controller : 'Test'
        })

        .state('test2',{
            url: '/test2',
            templateUrl: 'test/test2'
        })

        .state('test3',{
            url: '/test3',
            templateUrl: 'test/test3'
        })
}]);

//app/test/router.js end

})(angular,window,document);
(function(angular,window,document){
/**
 * Created by Deng on 2016-10-7.
 */
factoryFn.$inject = ["$resource"];
window.appModule.factory('testAPI',factoryFn);

function factoryFn($resource){
    var actions = {
        queryUser: {
            url: '/data/test.jsp',
            method: 'post'
        }
    }
    return $resource('', {_ajaxWrapOption: {}},actions);
}
})(angular,window,document);